* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  --small-spacing: 0.5rem;
  --medium-spacing: 0.75rem;
  --large-spacing: 1.0rem;
}

html,
body {
  height: 100%;
  overflow-y: auto;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  color: #333;
  background: #f5f5f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: var(--large-spacing);
}

p {
  margin: 1rem auto;
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

.chat-container {
  width: 100%;
  max-width: 960px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: var(--large-spacing);
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  border-radius: 12px 12px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header h1 {
  font-size: 2rem;
  color: #212529;
  word-break: break-word;
}

.chat-header img {
  vertical-align: middle;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--large-spacing);
  position: relative;
}

ol,
ul {
  margin: 0.5rem 0;
  padding-left: 2rem;
}

ol li,
ul li {
  padding: 0.25rem 0;
  margin: 0;
}

ol li::marker {
  color: #666;
  font-weight: 500;
}

ul li::marker {
  color: #666;
}

ol li:last-child,
ul li:last-child {
  padding-bottom: 0;
}

ol li:first-child,
ul li:first-child {
  padding-top: 0;
}

.message {
  padding: var(--medium-spacing);
  border-radius: 8px;
  word-wrap: break-word;
  background: var(--message-background);
}

.message-wrapper.user {
  --message-background: #e9ecef;
  margin-left: auto;
  max-width: 80%;
  width: max-content;
}

.message-wrapper.assistant {
  margin-right: auto;
  /* Not needed because of the message controls */
  margin-bottom: 0;
  max-width: 90%;
}

.message-wrapper.system {
  --message-background: #f8e3fa;
  margin-right: auto;
}

.message-wrapper {
  position: relative;
  overflow: visible;
  margin-bottom: 1rem;
}

.message-controls {
  margin-left: 0.5rem;
  margin-right: 0.5rem;
  display: inline-flex;
  gap: 0.25rem;
}

.message-wrapper.user .message-controls {
  right: 0;
}

.message-controls button, .copy-button {
  position: static;
  padding: 0.25rem;
  border-radius: 4px;
  border: 1px solid #dee2e6;
  background: white;
  transition: all 0.1s;
  cursor: pointer;
  box-sizing: content-box;
  width: 16px;
  height: 16px;
  font-size: 16px;
  line-height: 16px;
  text-align: center;
}

.message-controls button:hover,
.message-controls button:focus,
.copy-button:hover,
.copy-button:focus {
  border-color: #aaa;
}

.message-controls button img, .copy-button svg {
  width: 16px;
  height: 16px;
}

.message-controls button.toggled {
  box-shadow: inset 0 0 2px 1px rgba(0, 0, 0, 0.2);
}

.message-wrapper #info-container {
  font-size: 0.75rem;
  background: #f5f5f5;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  width: max-content;
  max-width: 100%;
  margin-left: 0.5rem;
  margin-right: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  vertical-align: top;
}

/* Add media query for small screens */
@media screen and (max-width: 576px) {
  .message-wrapper #info-container {
    margin-top: .25rem;
  }
}
.message-wrapper:not(:last-child) #info-container {
  margin-bottom: var(--large-spacing);
}

.message-wrapper span {
  display: inline-block;
}

.message img {
  max-width: 100%;
  height: auto;
}

.chat-input-container {
  padding: var(--large-spacing);
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: var(--small-spacing);
}

.chat-input {
  flex: 1;
  padding: var(--medium-spacing);
  border: 1px solid #dee2e6;
  border-radius: 6px;
  font-size: 1rem;
  outline: none;
  resize: none;
  max-height: 200px;
  min-height: 50px;
  line-height: 1.5;
  font-family: inherit;
  overflow-y: auto;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: #cbd5e1 transparent; /* Firefox */
}

.chat-input.drag-over {
  border-color: #0366d6;
  background-color: #f6f8fa;
}

/* Chrome, Edge, and Safari */
.chat-input::-webkit-scrollbar {
  width: 8px;
  background: transparent;
}

.chat-input::-webkit-scrollbar-track {
  background: transparent;
}

.chat-input::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 20px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* Only show scrollbar when needed */
.chat-input::-webkit-scrollbar-thumb:vertical {
  min-height: 30px;
}

.chat-input:not(:hover)::-webkit-scrollbar-thumb {
  background-color: transparent;
}

.chat-input:focus,
#completions-input:focus {
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.chat-input-container button,
.menu-trigger,
.completions-content button {
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.2s;
  box-sizing: content-box;
  min-width: 24px;
  min-height: 24px;
}

.chat-input-button-container {
  display: flex;
  flex-direction: column;
  align-self: flex-end;
  gap: var(--small-spacing);
}

.chat-input-button-container button img,
.menu-trigger img,
.completions-controls img {
  width: 24px;
  height: 24px;
}

.chat-input-button-row {
  display: flex;
  gap: var(--small-spacing);
}

.chat-input-button-row button,
.menu-trigger,
.completions-controls .settings-button {
  padding: var(--small-spacing);
  background: #9299a0;
}

.chat-input-button-row button:hover,
.menu-trigger:hover,
.completions-controls settings-button:hover {
  background: #5c636a;
}

.send-button,
button.complete-button {
  padding: 0.75rem 1.5rem;
  background-color: #0d6efd;
  font-size: 1rem;
}

.send-button:hover,
button.complete-button:hover {
  background-color: #0b5ed7;
}

.send-button:disabled,
button.complete-button:disabled {
  background: #6c757d;
  cursor: not-allowed;
}

.stop-button {
  padding: 0.75rem 1.5rem;
  background-color: #dc3545;
  font-size: 1rem;
}

.stop-button:hover {
  background-color: #bb2d3b;
}

.stop-button:disabled {
  background: #6c757d;
  cursor: not-allowed;
}

.message pre {
  margin: 1rem auto;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  padding: 0.5rem;
  border-radius: 4px;
  overflow-x: auto;
  position: relative;
  white-space: pre-wrap;
  min-height: 1.5rem;
  box-sizing: content-box;
}

.message blockquote {
  border-left: 4px solid #8b5cf6; /* Purple accent line */
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  background: rgba(139, 92, 246, 0.05); /* Very light purple background */
  border-radius: 0.375rem;
  font-style: italic;
  color: #4b5563; /* Slightly muted text */
}

/* Optional: Style nested blockquotes differently */
.message blockquote blockquote {
  border-left-color: #6d28d9; /* Darker purple for nested quotes */
  background: rgba(109, 40, 217, 0.05);
  margin-left: 1rem;
}

pre .copy-button {
  position: absolute;
  top: var(--small-spacing);
  right: var(--small-spacing);
  z-index: 1;
}

.copy-button svg {
  display: block;
}

.settings-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-panel {
  background: white;
  padding: 20px;
  border-radius: 8px;
  max-width: 500px;
  width: calc(100% - var(--large-spacing));
  max-height: calc(100% - var(--large-spacing));
  display: flex;
  flex-direction: column;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.settings-content {
  width: 100%;
  height: 100%;
  overflow: auto;
}

.settings-header button {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
}

.setting-item {
  margin-bottom: 20px;
}

.setting-item label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
}

.setting-item input {
  width: 100%;
  margin-bottom: 8px;
}

.setting-description {
  font-size: 0.9em;
  color: #666;
  margin-top: 4px;
}

.setting-item.disabled label,
.setting-item.disabled input,
.setting-item.disabled .setting-description {
  opacity: 0.5;
  cursor: not-allowed;
}

.setting-item.disabled input {
  pointer-events: none;
}

.setting-item.disabled {
  pointer-events: none;
  opacity: 0.8;
}

.setting-item.disabled input[type="range"] {
  background: #ccc;
}

.setting-item.disabled label,
.setting-item.disabled .setting-description {
  color: #999;
}

/* Styling for penalty range inputs */
.penalty-range {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 8px;
}

/* Chrome track styling */
.penalty-range::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  border-radius: 8px;
  background: linear-gradient(to right,
    #ff000088 0%, 
    #00000022 30%,
    #00000022 70%,
    #ff000088 100%
  );
}

/* Firefox track styling */
.penalty-range::-moz-range-track {
  width: 100%;
  height: 6px;
  border-radius: 8px;
  background: linear-gradient(to right,
    #ff000088 0%, 
    #00000022 30%,
    #00000022 70%,
    #ff000088 100%
  );
}

/* Chrome thumb styling */
.penalty-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #666;
  cursor: pointer;
  margin-top: -5px; /* Centers the thumb on the track */
}

/* Firefox thumb styling */
.penalty-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: #666;
  cursor: pointer;
}

/* Completions Interface */
.completions-container {
  width: 100%;
  height: 100%;
  max-width: 960px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
}

.completions-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--large-spacing);
}

#completions-input {
  flex: 1;
  padding: var(--large-spacing);
  margin-bottom: var(--large-spacing);
  border: 1px solid #dee2e6;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  outline: none ;
}

.completions-controls {
  display: flex;
  gap: var(--small-spacing);
}

.mode-dropdown {
  display: none;
}

.mode-trigger {
  display: none;
}

.mode-menu {
  display: none;
}

.mode-item {
  display: none;
}

.mode-switch {
  display: none;
}

.menu-dropdown {
  position: relative;
  display: inline-block;
  align-self: flex-start;
}

.menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: none;
  z-index: 1000;
  min-width: 180px;
}

.menu.show {
  display: block;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.9rem;
  color: #333;
}

.menu-item:hover {
  background: #f8f9fa;
}

.menu-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f0f0f0;
  color: #666;
}

.menu-item.disabled:hover {
  background: #f0f0f0;
}

@media print {

  html,
  body {
    height: auto !important;
    overflow-y: visible;
  }

  .noprint {
    display: none;
  }

  .copy-button {
    display: none;
  }

  .chat-container {
    box-shadow: none;
    height: auto !important;
    max-width: none !important;
    overflow: visible !important;
  }

  .chat-header {
    border: none !important;
    page-break-inside: avoid;
  }

  .chat-messages {
    overflow-y: visible;
    border: none !important;
    height: auto !important;
    max-width: none !important;
  }

  .message {
    max-width: none !important;
  }

  .message.user {
    border: 1px solid #999;
  }
}

.prefill-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: #eee;
}

.prefill-progress .progress-bar {
  height: 100%;
  background: #0d6efd;
  width: 0;
  transition: width 0.2s ease-out;
}

#prefill-status {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  gap: 10px;
}

.prefill-progress {
  flex: 1;
  height: 4px;
  background: #eee;
  border-radius: 2px;
  overflow: hidden;
}

.prefill-progress .progress-bar {
  height: 100%;
  background: #0d6efd;
  width: 0;
  transition: width 0.2s ease-out;
}

.ooc {
  vertical-align: middle;
  margin-left: 0.2rem;
}

@media (max-width: 768px) {
  html {
    --large-spacing: 0.5rem;
    --medium-spacing: 0.45rem;
    --small-spacing: 0.4rem;
  }

  body {
    padding: 0;
    background: white;
  }

  .chat-container {
    border-radius: 0;
    box-shadow: none;
    height: 100%;
  }

  .chat-header h1 {
    font-size: 1rem;
  }

  .chat-header img.logo {
    width: calc(24px + 2* 0.25rem);
    height: calc(24px + 2* 0.25rem);
  }

  .message-wrapper.user {
    max-width: 90%;
  }

  .message-wrapper.assistant {
    max-width: 100%;
  }

  .chat-input {
    line-height: 1.25;
  }

  .chat-input-button-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .chat-input-button-row {
    display: contents;
  }

  .chat-input-container .send-button,
  .chat-input-container .stop-button {
    padding: 0.25rem;
    font-size: 0;
    color: transparent !important;
    background-size: 24px;
    background-position: center;
    background-repeat: no-repeat;
  }

  .chat-input-container .send-button {
    background-image: url('./send.svg');
  }

  .chat-input-container .stop-button {
    background-image: url('./stop.svg');
  }

  .completions-controls .complete-button,
  .completions-controls .stop-button {
    padding: var(--small-spacing) var(--large-spacing);
  }
}
